#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main() {
    int a, b;
    while (scanf("%d %d", &a, &b) != EOF) 
    {
        if ((a % 4 == 0 && a % 100 != 0) || (a % 400 == 0))
        {
            int arr[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            printf("%d\n", arr[b]);
        }
        else
        {
            int arr[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            printf("%d\n", arr[b]);
        }
    }
    return 0;
}